var aberto;
$(document).ready(function(){


    function abrirMenu(obj){
        /*SUB-MENUS*/
        $(obj).next().animate({
            'top':'58px', 'opacity': 1
        },{ queue: false, duration: 600 }).show();
        /*FIM SUB-MENUS */
       /* if($(obj).has('.menu-drop')){
            $('.menu-drop',obj).stop(true,false).animate({
                'opacity':'0'

            })
        }*/

    }
    function fecharMenu(obj){
        /*** SUMIR SUB-MENUS ***/
        
          $(obj).parent().find('ol').stop(false,false).animate({
              'top':'45px',  'opacity': 0
          },{ queue: false, duration: 200 }).hide();
      
        /*** FIM SUMIR SUB-MENUS ***/

/*
        if($(obj).has('.menu-drop')){
            $('.menu-drop',obj).stop(false,false).animate({
                'opacity':'0.5'
            });
        }*/

    }

    $('.menu .item').mouseenter(function(){
        abrirMenu(this);
        // console.log('entrou no h3');
    });
    $('.menu .item').stop(false,false).mouseleave(function(){
      fecharMenu(this);
        
        // console.log('saiu do h3');
    });
    $('.menu li ol').stop(false,false).mouseenter(function(){

        abrirMenu($(this).parent().find('.item'));
        // console.log('entrou no ol');
    });
    $('.menu li ol').stop(false,false).mouseleave(function(){
    fecharMenu($(this).parent().find('.item'));
        // console.log('saiu do ol');
    });

  if(box){
      jQuery.facebox({ ajax: box });  
  }
  
    $('#nivo-slider').fadeIn(2000);
    $('#carrossel').fadeIn(2000);

    var teste = 0;


  //%%%%%%%%%%%%%%%% MODALBOX %%%%%%%%%%%%%%%%%    
   $('a[rel*=facebox]').facebox({
    loadingImage : 'imagens/icones_sistema/loading.gif',
    closeImage   : 'imagens/icones_sistema/closelabel.png'
   });
   //%%%%%%%%%%%%%%% FIM MODALBOX %%%%%%%%%%%%%%
   
  //%%%%%%%%%%%%% AUTO-SUGESTÃO %%%%%%%%%%%%%%  
  
  /*var options_xml = {
    script:"sugestoes.php?",
    varname:"input"
  };
  var as_xml = new AutoSuggest('busca', options_xml);*/  
   
  var options1 = {
    script:"sugestoes.php?json=true&",
    varname:"input",
    json:true
    //callback: function (obj) {}
  };
  var as_json = new AutoSuggest('busca', options1);
  //%%%%%%%%%%%%% FIM AUTO-SUGESTÃO %%%%%%%%%%%%%%
  
  
  //%%%%%%%%%%%%% BANNER %%%%%%%%%%%%%%
  $('#nivo-slider').nivoSlider({
    itemVisibleOutCallback: {onAfterAnimation: function(carousel, item, i, state, evt) { carousel.remove(i); }},
    effect:'fade', // Specify sets like: 'fold,fade,sliceDown,random'
       // slices:20, // For slice animations
       // boxCols: 8, // For box animations
       // boxRows: 4, // For box animations
        animSpeed:800, // Slide transition speed
        pauseTime:8000, // How long each slide will show
        startSlide:0, // Set starting Slide (0 index)
        directionNav:true, // Next & Prev navigation
        directionNavHide:true, // Only show on hover
        controlNav:false, // 1,2,3... navigation
       // controlNavThumbs:false, // Use thumbnails for Control Nav
       // controlNavThumbsFromRel:false, // Use image rel for thumbs
      //  controlNavThumbsSearch: '.jpg', // Replace this with...
       // controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
       // keyboardNav:false, // Use left & right arrows
        pauseOnHover:true, // Stop animation while hovering
       // manualAdvance:false, // Force manual transitions
        captionOpacity:0.8, // Universal caption opacity
        prevText: 'Anterior', // Prev directionNav text
        nextText: 'Próximo' // Next directionNav text
       /* beforeChange: function(){}, // Triggers before a slide transition
        afterChange: function(){}, // Triggers after a slide transition
        slideshowEnd: function(){}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){} // Triggers when slider has loaded*/
  
  });
  //%%%%%%%%%%%%% FIM BANNER %%%%%%%%%%%%%%


    //%%%%%%%%%%%%%% NEWS SCROLL HORIZONTAL %%%%%%%%%%%%%%%
   /* $('.news-pesquisa').ticker({
        speed: 0.10,           // The speed of the reveal
        ajaxFeed: false,       // Populate jQuery News Ticker via a feed
        feedUrl: false,        // The URL of the feed
        // MUST BE ON THE SAME DOMAIN AS THE TICKER
        //feedType: 'xml',       // Currently only XML
        htmlFeed: true,        // Populate jQuery News Ticker via HTML
        debugMode: true,       // Show some helpful errors in the console or as alerts
        // SHOULD BE SET TO FALSE FOR PRODUCTION SITES!
        controls: true,        // Whether or not to show the jQuery News Ticker controls
        titleText: 'Dicas: ',   // To remove the title set this to an empty String
        displayType: 'reveal', // Animation type - current options are 'reveal' or 'fade'
        direction: 'ltr',       // Ticker direction - current options are 'ltr' or 'rtl'
        pauseOnItems: 2000,    // The pause on a news item before being replaced
        fadeInSpeed: 600,      // Speed of fade in animation
        fadeOutSpeed: 300      // Speed of fade out animation
    });

    //%%%%%%%%%%%%%% NEWS SCROLL HORIZONTAL %%%%%%%%%%%%%%%
    $('.news-categoria').ticker({
        speed: 0.10,           // The speed of the reveal
        ajaxFeed: false,       // Populate jQuery News Ticker via a feed
        feedUrl: false,        // The URL of the feed
        // MUST BE ON THE SAME DOMAIN AS THE TICKER
        //feedType: 'xml',       // Currently only XML
        htmlFeed: true,        // Populate jQuery News Ticker via HTML
        debugMode: true,       // Show some helpful errors in the console or as alerts
        // SHOULD BE SET TO FALSE FOR PRODUCTION SITES!
        controls: true,        // Whether or not to show the jQuery News Ticker controls
        titleText: 'Dicas: ',   // To remove the title set this to an empty String
        displayType: 'reveal', // Animation type - current options are 'reveal' or 'fade'
        direction: 'ltr',       // Ticker direction - current options are 'ltr' or 'rtl'
        pauseOnItems: 2000,    // The pause on a news item before being replaced
        fadeInSpeed: 600,      // Speed of fade in animation
        fadeOutSpeed: 300      // Speed of fade out animation
    });*/





  //%%%%%%%%% CARROSSEL %%%%%%%%%%%
  $("#carrossel").carouFredSel({
    auto  : {
      items       : 1,
      duration    : 2000,
      easing      : "linear",
      pauseDuration  : 0,
      pauseOnHover  : true
    },
    height:80
  }).trigger("play");
  
  $("#carrossel-dir").click(function() {
    $("#carrossel").trigger("pause");
    $("#carrossel").trigger("configuration", ["direction", "right"]);
    $("#carrossel").trigger("play");
    return true;
  });
  
  $("#carrossel-esq").click(function() {
    $("#carrossel").trigger("pause");
    $("#carrossel").trigger("configuration", ["direction", "left"]);
    $("#carrossel").trigger("play");
    return true;
  });
  $("#carrossel-dir").hover(function(){
        $("#carrossel").stop();
    $("#carrossel").trigger("pause");
  },function(){
    $("#carrossel").trigger("play");
  });
  $("#carrossel-esq").hover(function(){
        $("#carrossel").stop();
    $("#carrossel").trigger("pause");
  },function(){
    $("#carrossel").trigger("play");
  });
    $("#carrossel").hover(function(){
        $(this).stop();
        $(this).trigger("pause");
    },function(){
        $(this).trigger("play");
    });
  //%%%%%%%%% FIM CARROSSEL %%%%%%%%%%%
  
  
    
  //%%%%%%%%%%%%%% TOOLTIPS %%%%%%%%%%%%%%%
  if(tooltips.length > 0){
    for(i=0;i<tooltips.length;i++){ 
       $('#tp'+(i+1)).qtip({
        position: { 
           my: 'bottom center', /* Use the corner... */
           at: 'top center' /*...and opposite corner*/
        },
        style: {
          classes: 'ui-tooltip-shadow ui-tooltip-youtube tooltip top-class'
        },
        content: {
           text: tooltips[i], 
           title: {
            text: tooltips_title[i],
            button: false
           }
        },hide: {
           fixed: true
        }
        
          
        
      });
    }
  }
  //%%%%%%%%%%%%%% FIM TOOLTIPS %%%%%%%%%%%%%%%









/*
  $('.box-sessoes').corner();
  $('.sessoes').corner();
  $('#carrossel-esq').corner();
  $('#carrossel-dir').corner();
  $('.caroufredsel_wrapper').corner();
  $('.lista-categorias li').corner();
  $('#carrossel li').corner();
  $('.lista-categorias li').hover(function(){
    $(this).css('border','1px solid #999');
    $(this).css('background','#f9f9f9');
  },
  function(){
    $(this).css('border','1px dotted #ddd');
    $(this).css('background','#ffffff');
  }
  );
  */
});


/*
  var uvOptions = {};
  (function() {
    var uv = document.createElement('script'); uv.type = 'text/javascript'; uv.async = true;
    uv.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'widget.uservoice.com/uR3CwxHcyseu5tsjwZ275w.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(uv, s);
  })();

*/


/*

function buscar(){
  alert('merda');
    var termo = document.getElementById('busca').value;
    alert(termo);
    //var filtro = document.getElementById("filtro").value;
    //var query_filtro="";
    
    //if(filtro > 0){ query_filtro= "&filtro="+filtro;}
    if(termo.length > 0 && termo != '<?=$valor_busca_default?>'){
      
      window.location.href = "<?=DIR_ROOT?>index.php?busca="+termo;//+query_filtro;  
    }
    
    return false;
      
}
function valor_input(obj,padrao){
  alert(obj.value);
  var valor = obj.value;
  if(valor == ""){
    obj.value = padrao;
  }else if(valor == padrao){
    obj.value = "";
  }  
}

$("#busca").watermark('<?=$valor_busca_default?>');
  

*/